﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Input;
using Chambills.Present.Core;
using Present.Commands.Async.Actions;
using Present.Commands.Fluent;

namespace Present.Commands.Sample
{
    public class AsyncCommandViewModel : NotifiableObject
    {
        public AsyncCommandViewModel()
        {
            AsyncCommand = Command.Async
                (
                AsyncAction.FromDelegates()
                            .Do(e =>
                                    {
                                        for(int n=0; n<100;n++)
                                        {
                                            if(CancelRequested)
                                                break;

                                            Thread.Sleep(10);
                                            ProgressAsPercent = n/100d;
                                        }
                                    })
                            .ToAction()
                ).ToCommand();
        }

        public bool CancelRequested { get; set; }

        public double ProgressAsPercent { get; set; }

        public ICommand AsyncCommand { get; private set; }
    }

}
